package HighMethod10;

/**
 * 一千万数据中找到最热门的十个查询串
 */
public class MaxDataTest2 {
    public static void main(String[] args) {

        String str1 = "xiaohongmao";
        String str2 = "你好";
        String str3 = "jingjing";
        String str4 = "shenxinyuan";

        //如何吧把字符串转化为整型
        int pos = Hash(StrSum(str1));
        System.out.println("str:" + pos);           //一、自定义哈希值
        System.out.println("str:" + str1.hashCode());       //二、使用java提供的hashCode()函数
    }

    private static int Hash(int x) {
        return x%97;
    }

    private static int StrSum(String str) {
        int res = 0;
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            res += res * 5 + chars[i];
        }
        return res;
    }
}
